package com.aaa.controller;

import com.aaa.entity.Playlist;
import com.aaa.service.PlaylistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/playlist")
public class PlaylistController {
    @Autowired
    private PlaylistService playlistService;
    private static final String IMG_PAGE="D:/upload/";
    @RequestMapping("/playtitle")
    public List<Playlist> playtitle(Integer lid){
        List<Playlist> playselectq = playlistService.playselectq(lid);
        return playselectq;
    }

    @RequestMapping("/playinsert")
    public Integer playinsert(Integer lid,Playlist playlist){
        Integer playinsert = playlistService.playinsert(lid,playlist);
        return playinsert;
    }
    @RequestMapping("/playlistsave")
    public Integer playlistsave(Playlist playlist){
        Integer playinsert = playlistService.playlistsave(playlist);
        return playinsert;
    }


    @RequestMapping("/playselect")
    public Playlist playselect(String ptitle){
        Playlist playselect = playlistService.playselect(ptitle);
        return playselect;
    }
    //图片上传
    @RequestMapping("/upload")
    public String upload(MultipartFile file){
        //生成唯一的文件名
        String imgname = UUID.randomUUID().toString();
        File file1=new File(IMG_PAGE+imgname);
        try {
            file.transferTo(file1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imgname;
    }
    //取消收藏
    @RequestMapping("/clickDown")
    public Integer clickDown(Integer mid,Integer pid){
        Integer playinsert = playlistService.pidmiddelete(mid,pid);
        return playinsert;
    }

    //收藏判断是否存在
    @RequestMapping("/midpidseleinsert")
    public Integer midpidseleinsert(Integer mid,Integer pid){
        Integer playinsert = playlistService.pidmidseleinsert(mid,pid);
        return playinsert;
    }
    //我喜欢的判断是否存在
    @RequestMapping("/lidpidseleinsert")
    public Integer lidpidseleinsert(Integer lid,Integer mid){
        Integer playinsert = playlistService.lidpidseleinsert(lid,mid);
        return playinsert;
    }
}
